<template>
  <div>
    <mini-head :title="$route.name" />
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select = "cut"
    />
  </div>
</template>

<script>
import { linkmanList } from '_api'
import MiniHead from '../../components/MiniHead.vue'
import { gettoken } from '../../utils'
export default {
  components: { MiniHead },
  data () {
    return {
      chosenAddressId: '-1',
      conner: []
    }
  },
  created () {
    this.initss()
  },
  methods: {
    initss () {
      linkmanList({
        token: gettoken()
      }).then((res) => {
        if (res.data.code === 0) {
          console.log(res, '???')
          this.conner = res.data.data.result
        }
      })
    },
    // 切换
    cut (e) {
      console.log(e)
      this.$router.replace({
        path: '/order',
        query: {
          id: e.id
        }
      })
    },
    // 编辑
    onEdit (e) {
      console.log(e)
      this.$router.replace({
        path: '/linkmanupdate',
        query: {
          id: e.id
        }
      })
    },
    // 增添
    onAdd () {
      this.$router.push('addlinkman')
    }
  },
  computed: {
    list () {
      const list = []
      this.conner.forEach(item => {
        const obk = {}
        for (const key in item) {
          if (key === 'linkMan') {
            obk.name = item[key]
          } else if (key === 'mobile') {
            obk.tel = item[key]
          } else {
            obk[key] = item[key]
          }
        }
        list.push(obk)
      })
      return list
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
